package com.imchen.cms.cmscore.service;

import com.imchen.cms.cmscore.dao.CommentsOwnTypeMapper;
import com.imchen.cms.cmscore.model.CommentsOwnType;
import com.imchen.cms.exception.CmsException;
import com.imchen.cms.utils.ServiceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author imchen
 * @create: 2019-02-01 18:34
 **/
@Service
public class CommentsOwnTypeService implements BaseService<CommentsOwnType> {

    @Autowired
    private CommentsOwnTypeMapper mapper;

    @Override
    public HashMap<String, Integer> add(CommentsOwnType commentsOwnType) throws CmsException {
        int count=mapper.insertSelective(commentsOwnType);
        int id=commentsOwnType.getId();
        return ServiceUtil.toAddMap(count,id);
    }

    public HashMap<String, Integer> addList(ArrayList<CommentsOwnType> list) throws Exception {
        int count=mapper.insertSelectiveList(list);
        return ServiceUtil.toAddMap(count,0);
    }

    @Override
    public CommentsOwnType findById(int id) {
        return mapper.selectByPrimaryKey(id);
    }

    public HashMap<String,Object> findByIdToMap(int id){
        CommentsOwnType commentsOwnType=mapper.selectByPrimaryKey(id);
        return ServiceUtil.toObjectMap(commentsOwnType,"commentsOwnType");
    }

    @Override
    public int removeById(int id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteById(int id) {
        return 0;
    }

    @Override
    public int update(CommentsOwnType commentsOwnType) {
        return mapper.updateByPrimaryKeySelective(commentsOwnType);
    }
}
